package com.maycur.ctrip.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.maycur.ctrip.util.Constant;
import com.maycur.ice.ctrip.TrainOrderDto;
import com.maycur.ice.ctrip.TrainTicketDto;
import org.joda.time.DateTime;

import java.util.List;

/**
 * Created by JoeyXin on 6/29/16.
 * 火车票订单信息
 */
public class TrainOrderInfoEntity {
    @JsonProperty(value = "BasicInfo")
    private TrainOrderBasicInfo basicInfo;

    @JsonProperty(value = "PassengerInfoList")
    private List<TrainPassengerInfoEntity> passengerInfoEntities;

    @JsonProperty(value = "TicketInfoList")
    private List<TrainTicketInfo> ticketInfos;

    public TrainOrderBasicInfo getBasicInfo() {
        return basicInfo;
    }

    public void setBasicInfo(TrainOrderBasicInfo basicInfo) {
        this.basicInfo = basicInfo;
    }

    public List<TrainPassengerInfoEntity> getPassengerInfoEntities() {
        return passengerInfoEntities;
    }

    public void setPassengerInfoEntities(List<TrainPassengerInfoEntity> passengerInfoEntities) {
        this.passengerInfoEntities = passengerInfoEntities;
    }

    public List<TrainTicketInfo> getTicketInfos() {
        return ticketInfos;
    }

    public void setTicketInfos(List<TrainTicketInfo> ticketInfos) {
        this.ticketInfos = ticketInfos;
    }

    public TrainOrderDto convertToOrderDto() {
        TrainOrderDto trainOrderDto = new TrainOrderDto();


        trainOrderDto.orderId = this.basicInfo.getOrderId();
        //trainOrderDto.journeyNo = TBD
        trainOrderDto.consumeAmount = this.basicInfo.getTotalAmount().floatValue();
        //trainOrderDto.consumeCcy = TBD;
        trainOrderDto.consumeDateTime = new DateTime(this.basicInfo.getOrderedAt()).toString(Constant.DATE_TIME_FORMAT);
        //trainOrderDto.consumeCity = TBD;
        trainOrderDto.orderStatus = this.basicInfo.getOrderStatusDesc();
        trainOrderDto.auditedStatus = this.basicInfo.getAuditedStatusDesc();

        trainOrderDto.trainTicketDtoSeq = new TrainTicketDto[ticketInfos.size()];

        for(int i = 0; i< ticketInfos.size(); i++) {
            TrainTicketDto trainTicketDto = new TrainTicketDto();

            trainTicketDto.trainName = ticketInfos.get(i).getTrainName();
            trainTicketDto.firstSeatTypeName = ticketInfos.get(i).getFirstSeatTypeName();
            trainTicketDto.ticketAmount = ticketInfos.get(i).getTicketAmount().floatValue();
            trainTicketDto.departureDateTime =  new DateTime(ticketInfos.get(i).getDepartureAt()).toString(Constant.DATE_TIME_FORMAT);
            trainTicketDto.arrivalDateTime = new DateTime(ticketInfos.get(i).getArrivalAt()).toString(Constant.DATE_TIME_FORMAT);
            trainTicketDto.departureCityName = ticketInfos.get(i).getDepartureCityName();
            trainTicketDto.arrivalCityName = ticketInfos.get(i).getArrivalCityName();

            trainOrderDto.trainTicketDtoSeq[i] = trainTicketDto;
        }

        return trainOrderDto;

    }
}
